/*
*********************************************************************************************************
*
*	
*	
*	
*
*	Copyright (C), 2013-2014, 
*********************************************************************************************************
*/

#ifndef _BSP_H_
#define _BSP_H

#include "stm32f4xx.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_tim.h"
#include "stm32f4xx_hal_spi.h"
#include "stm32f4xx_hal_sdram.h"
#include "stm32f4xx_hal.h"
#include "sim_i2c.h"

    #define BACKUP_SRAM_SIZE		(4*1024)		//备份SRAM大小

typedef enum
{
	USR_SPI1 = 0,
	USR_SPI2 = 1,
	USR_SPI3 = 2,
	USR_SPI4 = 3,
	USR_SPI5 = 4,
}SPI_PORT_E;

	//red
	#define LED_FAULT_PORT       	GPIOB
	#define LED_FAULT_PIN        	GPIO_PIN_15
    #define LED_FAULT_ON		 	HAL_GPIO_WritePin(LED_FAULT_PORT, LED_FAULT_PIN,1)
	#define LED_FAULT_OFF   	 	HAL_GPIO_WritePin(LED_FAULT_PORT, LED_FAULT_PIN,0)

	//green
	#define LED_RUN_PORT       		GPIOH
	#define LED_RUN_PIN        		GPIO_PIN_12
    #define LED_RUN_ON		 		HAL_GPIO_WritePin(LED_RUN_PORT, LED_RUN_PIN,1)
	#define LED_RUN_OFF   	 		HAL_GPIO_WritePin(LED_RUN_PORT, LED_RUN_PIN,0)

	#define LED_LAN_PORT       		GPIOD
	#define LED_LAN_PIN        		GPIO_PIN_11
    #define LED_LAN_ON		 		HAL_GPIO_WritePin(LED_LAN_PORT, LED_LAN_PIN,0)
	#define LED_LAN_OFF   	 		HAL_GPIO_WritePin(LED_LAN_PORT, LED_LAN_PIN,1)

	#define LED_RS4851_PORT       	GPIOD
	#define LED_RS4851_PIN        	GPIO_PIN_12
    #define LED_RS4851_ON		 	HAL_GPIO_WritePin(LED_RS4851_PORT, LED_RS4851_PIN,0)
	#define LED_RS4851_OFF   	 	HAL_GPIO_WritePin(LED_RS4851_PORT, LED_RS4851_PIN,1)

	#define LED_RS4852_PORT       	GPIOD
	#define LED_RS4852_PIN        	GPIO_PIN_13
    #define LED_RS4852_ON		 	HAL_GPIO_WritePin(LED_RS4852_PORT, LED_RS4852_PIN,0)
	#define LED_RS4852_OFF   	 	HAL_GPIO_WritePin(LED_RS4852_PORT, LED_RS4852_PIN,1)

	#define LED_CARD_PORT       	GPIOG
	#define LED_CARD_PIN        	GPIO_PIN_2
    #define LED_CARD_ON		 		HAL_GPIO_WritePin(LED_CARD_PORT, LED_CARD_PIN,0)
	#define LED_CARD_OFF   	 		HAL_GPIO_WritePin(LED_CARD_PORT, LED_CARD_PIN,1)

	#define MOTOR_DIR_PORT       	GPIOG
	#define MOTOR_DIR_PIN        	GPIO_PIN_7
    #define MOTOR_DIR_UP		 	HAL_GPIO_WritePin(MOTOR_DIR_PORT, MOTOR_DIR_PIN,1)
	#define MOTOR_DIR_DOWN   	 	HAL_GPIO_WritePin(MOTOR_DIR_PORT, MOTOR_DIR_PIN,0)

	extern void USR_GPIO_Config(void);   //io
	extern void USR_PWM_Config(uint16_t arr,uint16_t psc);       //wpm
	extern void TIM_SetTIM3Compare4(uint8_t channel,uint8_t duty);  //
	extern void MOTOR_CTL(uint8_t dir,uint8_t duty);   // 
	extern void USR_SPI_Init(void);   //spi
	extern void USR_SPI_SetSpeed(SPI_PORT_E ucPORT,uint8_t SPI_BaudRatePrescaler);//spi
	extern uint8_t USR_SPI_ReadWriteByte(SPI_PORT_E ucPORT,uint8_t TxData);//
	extern HAL_StatusTypeDef USR_SPI_WriteByte(SPI_PORT_E ucPORT,uint8_t TxData);//

    extern void BackupSRAM_Init(void);												//备份域SRAM初始化
    extern uint16_t BackupSRAM_WriteData(uint8_t *pData, uint16_t AddrOffset, uint16_t DataLen);		//写入数据到备份SRAM中
    extern uint16_t BackupSRAM_ReadData(uint8_t *pData, uint16_t AddrOffset, uint16_t DataLen);		//从备份SRAM中读取数据

#endif
